<?php

namespace App\Service\Impl;

if (!defined('IN_PX'))
    exit;

use App\Service\Collection;
use App\Repository;
use App\Tools\Auxi;
use App\Tools\Html;
use Phoenix\Http\RequestMethod;
use Phoenix\Support\MsgHelper;

/**
 * 用户表服务类
 * v1.0.0 开发了登录注册完善信息修改忘记密码功能
 */
class CollectionImpl implements Collection {

    const VERSION = '1.0.0';

    //服务层组件
    private function __Service($value = 'collection') {}

    private function __Value($__PACKAGE__, $__ROOT__, $__RM__, $setting, $cfg, $__LANGUAGE_ID__) {}

    private function __Inject($session, $cache, Repository\Collection $repoColl) {}

    public function collection($post) {
        $userInfo = $this->session->member;
        $data = array();
        $data['member_id'] = $userInfo['member_id'];
        $data['archives_id'] = $post['collection'];
        $data['is_type'] = $post['type'];
        $data['language'] = $post['language'];
        $data['is_status'] = 1;
        $data['add_date'] = time();
        $data['release_date'] = $data['add_date'];
        if ($userInfo) {
            if ($this->repoColl->chkExists($data)) {
                $return = $this->repoColl->updateCollection($data);
            } else {
                $return = $this->repoColl->addCollection($data);
            }
            if ($return) {
                return 0;
            } else {
                return 11009;
            }
        } else {
            return 11018;
        }
    }

    public function deleteCollection($post) {
        if (!isset($post['collection']) || $post['collection'] == '' || $post['collection'] == 0) {
            return 11019;
        }
        $userInfo = $this->session->member;
        $data = array();
        $data['member_id'] = $userInfo['member_id'];
        $data['collection_id'] = trim($post['collection'], ',');
        $data['is_type'] = $post['type'];
        $data['release_date'] = time();
        if ($userInfo) {
            $return = $this->repoColl->deleteCollection($data);
            if ($return) {
                return 0;
            } else {
                return 11009;
            }
        } else {
            return 11018;
        }
    }
}
